
var Pet = Pet || { 'settings': {"dhtmlMenu_useEffects": 1, "dhtmlMenu_hideSiblings": 1}, 'behaviors': {} };
Pet.dhtmlMenu = {};
var dhtmlRun = false;

Pet.attachBehaviors = function(context) {
	context = context || document;
  	// Execute all of them.
	jQuery.each(Pet.behaviors, function() {this(context);});
};

/**
 * Initialize the module's JS functions
 */
Pet.behaviors.dhtmlMenu = function(context) {
  // Do not run this function more than once.
  if (dhtmlRun) return;
  else dhtmlRun = true;
  // Get the Cookie's data
  var cookievalue = Pet.dhtmlMenu.cookieGet();

  // If there is any menus that should be expanded,
  // do it now
  if (cookievalue != '') {
    var cookieList = cookievalue.split(',');
    for (var i = 0; i < cookieList.length; i++) {
      if (!document.getElementById(cookieList[i])) {
        cookieList.splice(i, 1);
      }
      else {
        submenu = document.getElementById(cookieList[i]);
        menu = document.getElementById('menu-' + cookieList[i]);
        $(menu).removeClass('collapsed').addClass('expanded');
        $(submenu).removeClass('sub-collapsed').addClass('sub-expanded');
        $(submenu).show();
        $(submenu).css('display', 'block');
      }
    }
  }

  // Add jQuery effects (click and double click) to all menu items
  $('ul.menu li[@class!="leaf"] > a').each(function() {
    if ($(this).siblings('div.submenu').length > 0) {
      $(this)
      .css({display: 'block', zIndex: 2})
      .dblclick(function(e) {
        window.location = this.href;
      })
      .click(function(e) {
        id = $(this).parents()[0].id.replace('menu-', '');
        Pet.dhtmlMenu.switchMenu(id, $(this).parents()[0]);
        return false;
      });
    }
  });
}

/**
 * Grabs the cookie data.
 *
 * @return
 *   String. A list, separated by comma, of all menu IDs
 *   that should be expanded.
 */
 
Pet.dhtmlMenu.cookieGet = function() {
  var string = 'dhtml_menu=';
  var returnvalue = '';

  // If there is a previous instance of this cookie
  if (document.cookie.length > 0) {

    // Get the number of characters that have the list of values
    // from 'dhtml_menu' index.
    offset = document.cookie.indexOf(string);

    // If its positive, there is a list!
    if (offset != -1) {
      offset += string.length;
      var end = document.cookie.indexOf(';', offset);
      if (end == -1) {
        end = document.cookie.length;
      }

      // Get a list of all values that are saved on 'dhtml_menu='
      returnvalue = unescape(document.cookie.substring(offset, end));
    }
  }

  return returnvalue;
}

/**
 * Saves the states of the menus.
 */
Pet.dhtmlMenu.cookieSet = function() {
  var menus = '';

  // Get a list of menu IDs, saparated by comma
  $('div.submenu').each(function(i) {
    if ($(this).hasClass('sub-expanded')) {
      if (menus != '') {
        menus += ',';
      }
      menus += this.id;
    }
  });

  // Save this values on the cookie
  document.cookie = 'dhtml_menu=' + escape(menus) + ';path=/';
}

/**
* Hide all submenus
*/
Pet.dhtmlMenu.hideSiblings = function(parent_menu) {
  $(parent_menu).siblings('.expanded').each(function() {
    id = $(this).attr('id').replace('menu-', '');
    Pet.dhtmlMenu.switchMenu(id, this);
  });
};

/**
 * Changes the state of a submenu from open to close.
 *
 * @param submenu
 *   String. The submenu ID (including the "#")
 * @param parent_menu
 *   String. The parent item ID (including the "#")
 */

Pet.dhtmlMenu.switchMenu = function(submenu, parent_menu) {
  submenu = document.getElementById(submenu);

  // First, see if the menu is already expanded or collapsed,
  // and perform the opposing effect
  if($(parent_menu).is('.expanded')) {

    // If the user wants the Fading effects, use it,
    // otherwise, simply make the menu disapear
    //if (Pet.settings.dhtmlMenu_useEffects) {
    // $(submenu).hide('fast');
    //}else {
    // $(submenu).css('display', 'none');
    //}
	
	$(submenu).css('display', 'none');
	
    // Set the parent menu item as collapsed
    $(parent_menu).removeClass('expanded').addClass('collapsed');
    $(submenu).removeClass('sub-expanded').addClass('sub-collapsed');
  } else {
    if (Pet.settings.dhtmlMenu_hideSiblings) {
      Pet.dhtmlMenu.hideSiblings(parent_menu);
    }

    // If the user wants the Fading effects, use it,
    // otherwise, simply make the menu apear
    if (Pet.settings.dhtmlMenu_useEffects) {
      $(submenu).show('fast');
    }
    else {
      $(submenu).css('display', 'block');
    }
    $(parent_menu).removeClass('collapsed').addClass('expanded');
    $(submenu).removeClass('sub-collapsed').addClass('sub-expanded');
  }

  // After all changes, save the current state
  // of the menus, so other pages will load and use
  // this new layout
  Pet.dhtmlMenu.cookieSet();
}

/*-----------------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------------*/
/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
/*
Pet.behaviors.scrollTo = function(context) {
	
	$('#feedback-button a, #menu-enviar-feedback a').click(function(){
		$.scrollTo( '#block-user_feedback-feedback', 800 );
	});

};
*/
/*-----------------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------------*/
Pet.behaviors.setUpFonts = function(context)
{
	
}
/*-----------------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------------*/
Pet.behaviors.sliders = function(context) {
	
	// http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
	var settings = {			
		prevId: 		'prevBtn',
		prevText: 		'',
		nextId: 		'nextBtn',	
		nextText: 		'',
		controlsShow:	true,
		controlsBefore:	'',
		controlsAfter:	'',	
		controlsFade:	false,
		firstId: 		'firstBtn',
		firstText: 		'First',
		firstShow:		false,
		lastId: 		'lastBtn',	
		lastText: 		'Last',
		lastShow:		false,				
		vertical:		false,
		speed: 			800,
		auto:			true,
		pause:			6000,
		continuous:		true
	};
   $("#slider").easySlider(settings);
    
};
/*-----------------------------------------------------------------------------------------------------------*/
Pet.behaviors.fancyBox = function(context) 
{
	$("#lastest-images a[rel=group], #profile-user-box .gallery .picture a[rel=group],#sidebar-right .block-poll .poll .picture a").fancybox({
		'width'				: '90%',
		'height'			: '90%',
		'speedIn'			: 0,
		'speedOut'			: 0,
		'changeFade'		: 0,
		'changeSpeed'		: 0,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'overlayShow'		: true,
		'showNavArrows'		: true,
		'overlayColor'		: '#fff',
		'overlayOpacity'	: 0.5,
		'titlePosition'	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return "";
				//return '<a title="Claudia" href="/Dropbox/pet.marcelo/2011/www.pateaeltablero.com.ar/web/beta/users/claudia"><img src="/Dropbox/pet.marcelo/2011/www.pateaeltablero.com.ar/web/beta/sites/default/files/pictures/picture-10.jpg" alt="Claudia" title="Claudia"></a>'
				//return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
	$("#edit-legal-accept-wrapper a").fancybox({'width': 800,'height': '90%','type' : 'iframe'});
	
	$(".node.full .field-items a.imagecache").fancybox({'width': '90%','height': '90%','overlayColor': '#000','overlayOpacity'	: 0.9,'speedIn': 0,'speedOut': 0});
};
/*-----------------------------------------------------------------------------------------------------------*/

Pet.behaviors.tabNavegators = function(context) {
	
	$(".tab-navegator ul.tabs").hide();
	return;
	$(".tab-navegator .tab-content").hide();
	$(".tab-navegator ul.tabs li:first").addClass("active").show();
	$(".tab-navegator .tab-content:first").show();

	$(".tab-navegator ul.tabs li").click(function(){
		$(".tab-navegator ul.tabs li").removeClass("active");
		$(this).addClass("active");
		$(".tab-navegator .tab-content").hide();
		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn();
		return false;
	});
	
};

/*TOOL TIPS ------------------------------------------------------------------------------------------*/
Pet.behaviors.tooltips = function(context) 
{
	$.fn.qtip.styles.qTipStyle = {
		background: '#333',
		color: '#fff',
		textAlign: 'center'
	};
	
	$(" #page-options-box .super-button").each(function(){
		$(this).qtip({
			content: $(".tooltip-data",this).html(),
			style: {
					name:'qTipStyle',
					padding: 5,
					border: { width: 0 ,radius: 3, color:'#333'},
					width: 200,
					tip: {corner:'bottomMiddle',size: {x: 10,y : 5 }}
			},
			position: { adjust: { x: -123, y: -110 } },
			show: { delay: 0 ,effect: { length: 0 }},
			hide: { delay: 0 ,effect: { length: 0 }}
		});
	});
	
	$("#profile-user-box  ul.links.inline.contactos li, .link-button.contact-button ").each(function(){
		$(this).qtip({
			content: $(".tooltip-data",this).html(),
			style: {
				name:'qTipStyle',
				padding: 3,
				border: { width: 0 ,radius: 3, color:'#333'},
				tip: { corner:'topMiddle',size: {x: 5, y : 3 }}
			},
			position: { 
				corner: { target: 'bottomMiddle', tooltip:'topMiddle' } ,
				adjust: { x: 0 , y: 0 }
			},
			show: { delay: 0 ,effect: { length: 0 }},
			hide: { delay: 0 ,effect: { length: 0 } }
		});
    });
	
	$('.picture.amigos img[title], .clock[title]').qtip({
		style: {
			name:'qTipStyle',
			padding: 3,
			border: { width: 0 ,radius: 1, color:'#333'},
			tip: { corner:'topMiddle', size: {x: 5, y : 3 }}
		},
		position: { 
			corner: { target: 'bottomMiddle', tooltip:'topMiddle' } ,
			adjust: { x: 0 , y: 0 }  
		},
		show: { delay: 0 ,effect: { length: 0 }},
		hide: { delay: 0 ,effect: { length: 0 }}
	});
	
	$('.sidebar ul li a[title]').qtip({
		style: {
			name:'qTipStyle',
			padding: 3,
			border: { width: 0 ,radius: 1, color:'#333'},
			tip: { corner:'leftMiddle',size: {x: 5, y : 10 }}
		},
		position: { 
			corner: { target: 'rightMiddle', tooltip:'leftMiddle' } ,
			adjust: { x: 0 , y: 0 }
		},
		show: { delay: 0 ,effect: { length: 0 }},
		hide: { delay: 0 ,effect: { length: 0 }}
	});
	
	$('#center #user-menu-box ul li a[title], .see-more a[title]').qtip({
		style: {
			name:'qTipStyle',
			padding: 3,
			border: { width: 0 ,radius: 3, color:'#333'},
			tip: { corner:'bottomMiddle',size: {x: 5, y : 3 }}
		},
		position: { 
			corner: { target: 'topMiddle', tooltip:'bottomMiddle' } ,
			adjust: { x: 0 , y: -10 }
		},
		show: { delay: 0 ,effect: { length: 0 }},
		hide: { delay: 0 ,effect: { length: 0 }}
	});
	
	$('#header-region #user-menu-box ul li a[title], .see-more a[title]').qtip({
		style: {
			name:'qTipStyle',
			padding: 3,
			border: { width: 0 ,radius: 1, color:'#333'},
			tip: { corner:'topMiddle', size: {x: 5, y : 3 }}
		},
		position: { 
			corner: { target: 'bottomMiddle', tooltip:'topMiddle' } ,
			adjust: { x: 0 , y: 20 }  
		},
		show: { delay: 0 ,effect: { length: 0 }},
		hide: { delay: 0 ,effect: { length: 0 } }
	});
   
};

/*-----------------------------------------------------------------------------------------------------------*/
$(document.documentElement).addClass('js');// Global Killswitch on the <html> element
document.cookie = 'has_js=1; path=/';// 'js enabled' cookie

// Attach all behaviors.
$(document).ready(function() {
	 Pet.attachBehaviors(this);
});

var timeout = 0; //Internet Explorer Fix

function removeMessages() {
	clearTimeout(timeout);
	$("div.status, div.warning, div.error").animate({ backgroundColor: "#fff", height: "10" , opacity: "0" }, "slow").animate({ opacity: "hide" }, "fast")
}


$(document).ready(function() {
	
	
	/*
	*/
	
	//timeout = setTimeout(removeMessages,8000);
	$("div.status, div.warning, div.error").click(function(){
		$(this).animate({ backgroundColor: "#fff", height: "10" , opacity: "0" }, "fast").animate({ opacity: "hide" }, "fast")
	});
	
	$(".node.teaser").hover(function(){
		$(this).find(".meta ul").css({display:"block",opacity: "1"});
	}, function() {
		$(this).find(".meta ul").css({opacity: "0", display: "none" });
	});
	$(".node.teaser .meta ul").css({ display : "none" });
	$(".node.teaser .meta ").css({"min-height":"35px"});
	
	/*-----------------------------------------------------------------------------------------------------------*/

	$("#profile-user-box .links.inline.contactos #ver-trabajos").click(function(){
		$("#user-personal-information-box .tab-navegator #trabajos").click();
    	return false;
	});
	
	/*-----------------------------------------------------------------------------------------------------------*/
	
	$('textarea').elastic();
	$('textarea').trigger('update');
	
	
	
});

